package com.example.administrator.myapplication.net;

import android.text.TextUtils;

import java.net.URL;

public class HttpUrl {
    String protocol;
    String host;
    String file;
    int port;

    public HttpUrl(String url) throws Exception {
        URL httpUrl = new URL(url);
        host = httpUrl.getHost();
        file = httpUrl.getFile();
        file = TextUtils.isEmpty(file) ? "/" : file;
        port = httpUrl.getPort();
        port = port == -1 ? httpUrl.getDefaultPort() : port;
        protocol = httpUrl.getProtocol();
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }
}
